
var i=1;


$(document).ready(function () {
    compute();
});



function unfold() {
    if(i%2) {
        $("#shopping_commend_sort").hide();
        $(".shopping_commend_right img").attr('src', "images/shopping_arrow_down.gif");
    }
    else {
        $("#shopping_commend_sort").show();
        $(".shopping_commend_right img").attr('src', "images/shopping_arrow_up.gif");
    }
    i++;
}

function del(id) {
    var id_str="shoppingProduct_0"+id;
    $("#"+id_str).remove();
    if(id===0)
        for(var i=1;i<7;i++)
            del(i);
    compute()
}

function compute() {
    var trs=$("#myTableProduct").find("tr");
    console.log(trs);
    var data=[];
    var point_sum=0;
    var value_dangdang_sum=0;
    var value_sum=0;
    for(var i=0;i<trs.length;i++){
        var tds=$(trs[i]).find("td");
        console.log(i,tds);
        value_td=$(tds[3]).find("label").textContent;
        var point=tds[1].textContent;
        var value=$(tds[2]).find("label")[0].textContent;
        var value_dangdang=$(tds[3]).find("label")[0].textContent;
        var num=parseInt($(tds[4]).find("input")[0].value);
        data.push([point,value,num]);
        point_sum+=point*num;
        value_sum+=value*num;
        value_dangdang_sum+=value_dangdang*num;
    }
    console.log(data);
    $("#product_total").text(value_dangdang_sum);
    $("#product_save").text(value_sum-value_dangdang_sum);
    $("#product_integral").text(point_sum);
}